package hander

import (
	"api-client/basic/api/request"
	__ "api-client/proto"
	"github.com/gin-gonic/gin"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
	"net/http"
)

func CreateGood(c *gin.Context) {
	var req request.CreateGood
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "参数验证失败",
			"data": nil,
		})
		return
	}

	conn, err := grpc.NewClient("127.0.0.1:8803", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()

	client := __.NewUserClient(conn)

	login, _ := client.CreateGood(c, &__.CreateGoodRequest{
		UserId: req.UserId,
		GoodId: req.GoodId,
		Num:    req.Num,
	})



	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "订单创建成功",
		"data": login,
	})



}
